fix: prevent silent None return in run_with_retry when max_retries < 1#198
Open
amathxbt wants to merge 2 commits intoOpenGradient:mainfrom
Open
fix: prevent silent None return in run_with_retry when max_retries < 1#198amathxbt wants to merge 2 commits intoOpenGradient:mainfrom
amathxbt wants to merge 2 commits intoOpenGradient:mainfrom
Conversation
Previously, calling run_with_retry with max_retries=0 (or any value that resolves to < 1) caused range(0) to produce an empty loop body, silently returning None instead of executing the transaction. Downstream callers assign the result directly (e.g. result = run_with_retry(...)) so a None return causes a confusing AttributeError or TypeError far from the actual source of the problem. Fix: - Add explicit ValueError guard when effective_retries < 1 - Add unreachable-but-explicit RuntimeError after loop as a safety net
Collaborator
|
Hi thanks for the contribution! Would you mind merging from main? Thank you |
The PR branch had an empty _utils.py due to a merge issue. This commit: 1. Restores all existing code from upstream main 2. Adds ValueError guard when effective_retries < 1 3. Adds RuntimeError safety net after the retry loop Fixes the silent None return bug as described in the PR.
Contributor
Author
|
Hey @adambalogh — thanks for the feedback! Done Here is what was done to address your request: Merged from
|
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
run_with_retryin_utils.pysilently returnsNonewhenmax_retriesresolves to0or any value less than1.All callers assign the result directly:
A
Nonereturn causes a downstreamAttributeErrororTypeErrorthat is confusing to debug — the real mistake (passingmax_retries=0) is far removed from where the crash occurs.Root Cause
No validation of
effective_retriesbefore entering the loop.Fix
Two-layer defense:
ValueErrorimmediately ifeffective_retries < 1:RuntimeErrorafter the loop (theoretically unreachable, but prevents any future refactor from silently returningNone):Impact
ValueErrorat the call site instead of a crypticNoneTypeerror downstreammax_retriesvalues